<?php

namespace app\index\controller;

use app\admin\model\Article;
use app\common\controller\Frontend;
use app\common\model\Category;

class Index extends Frontend
{

    protected $noNeedLogin = '*';
    protected $noNeedRight = '*';
    protected $layout = '';

    public function index()
    {
        $where = [
            'category_type' => 'goods',
            'status_data' => 1,
        ];
        $field = ['id, name, image, weigh'];
        $goodsList1 = Article::where($where)
            ->order('weigh desc, id desc')
            ->field($field)
            ->limit(16)
            ->select();

        $goodsList2 = Article::where($where)
            ->order('updatetime desc')
            ->field($field)
            ->limit(16)
            ->select();

        // 咨询列表
        $newsCateId = Category::where(['nickname' => '/news'])->value('id');
        $articleList1 = [];
        if ($newsCateId) {
            $articleList1 = Article::where(['status_data' => 1, 'category_id' => $newsCateId])
                ->field('id, name')
                ->order('weigh desc, id desc')
                ->limit(8)
                ->select();
        }
        // 行业动态列表
        $dynamicsCateId = Category::where(['nickname' => '/dynamics'])->value('id');
        $articleList2 = [];
        if ($newsCateId) {
            $articleList2 = Article::where(['status_data' => 1, 'category_id' => $dynamicsCateId])
                ->field('id, name')
                ->order('weigh desc, id desc')
                ->limit(8)
                ->select();
        }

        $this->assign('goodsList1', $goodsList1);
        $this->assign('goodsList2', $goodsList2);
        $this->assign('articleList1', $articleList1);
        $this->assign('articleList2', $articleList2);
        return $this->fetch();
    }
}
